#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * DNS WINS Record Structure
 *      Represents a DNS Windows Internet Name Service (WINS) record.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;
using namespace System::Net;

namespace Adaptive
{
	namespace Network
	{
		namespace Dns
		{
			/// <summary>
			/// Represents a DNS Windows Internet Name Service (WINS) record.
			/// </summary>
			public value struct DnsWINSRecord
			{
			internal:
				/// <summary>
				/// Initializes a new instance of the class from the unmanaged record.
				/// </summary>
				/// <param name="record"> A pointer to a DNS_RECORD structure whose contents are to be copied.</param>
				DnsWINSRecord(DNS_RECORD* record)
				{
					int count = 0;

					if (record == NULL)
					{
						MappingFlag = 0;
						LookupTimeout = 0;
						CacheTimeout = 0;
						WinsServerCount = 0;
						WinsServers = nullptr;
					}
					else
					{
						MappingFlag = record->Data.WINS.dwMappingFlag;
						LookupTimeout = record->Data.WINS.dwLookupTimeout;
						CacheTimeout = record->Data.WINS.dwCacheTimeout;
						WinsServerCount = sizeof(record->Data.WINS.WinsServers) / sizeof(IP4_ADDRESS);
						WinsServers = gcnew array<IPAddress^>(WinsServerCount);

						for(count = 0; count < WinsServerCount;count++)
							WinsServers[count] = gcnew IPAddress( (int)(DWORD) record->Data.WINS.WinsServers[count]);
						
					}
				}
			private:
				/// <summary>
				/// Static constructor.
				/// </summary>
				static DnsWINSRecord()
				{
				}

			public:
				/// <summary>
				/// WINS mapping flag that specifies whether the record must be included into the zone replication. 
				/// It may have only two values: 0x80000000 and 0x00010000 corresponding to the replication and no-replication 
				/// (local record) flags, respectively.
				/// </summary>
				/// <value>
				/// A value indicating replication or no replication, or zero.
				/// </value>
				int MappingFlag;  
				/// <summary>
				/// Time, in seconds, that a DNS Server attempts resolution using WINS lookup.
				/// </summary>
				/// <value>
				/// Loookup timeout value.
				/// </value>
				int LookupTimeout;  
				/// <summary>
				/// Time, in seconds, that a DNS Server using WINS lookup may cache the WINS Server's response.
				/// </summary>
				/// <value>
				/// Cache timeout value.
				/// </value>
				int CacheTimeout;  
				/// <summary>
				/// Number of WINS Servers listed.
				/// </summary>
				/// <value>
				/// The number of WINS Servers returned.
				/// </value>
				int WinsServerCount;  
				/// <summary>
				/// The list of WINS Server IP addresses.
				/// </summary>
				/// <value>
				/// An <see cref="IPAddress"/> array containing the list of WINS Server IP addresses.
				/// </value>
				array<IPAddress^>^ WinsServers;
			};
		}
	}
}